package com.qdc.datacenters.domain.vo.chatmsg;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * @author danmo
 * @date 2024-03-06 11:36
 **/
@Schema
@Data
public class ChatMsgListBaseVo {

    @Schema(description = "发送时间")
    private String msgTime;

    @Schema(description = "发送类型")
    private String msgType;

    @Schema(description = "文本消息")
    private String msgText;


    public String getMsgTime() {
        long diffDate = DateUtil.between(DateUtil.parseDate(this.msgTime), DateUtil.date(), DateUnit.DAY);
        if (diffDate == 0L) {
            return DateUtil.parseTime(this.msgTime).toTimeStr();
        } else if (diffDate == 1) {
            return "昨天";
        } else if (1 < diffDate && diffDate <= 7) {
            return DateUtil.dayOfWeekEnum(DateUtil.parseDate(this.msgTime)).toChinese();
        } else {
            return DateUtil.parseDate(this.msgTime).toDateStr();
        }
    }
}
